import java.util.ArrayList;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.state.StateBasedGame;


public class Entity {

	String id;
	
	Vector2f position;
	float scale;
	float rotation;
	
	RenderComponent renderComponent = null;
	
	ArrayList<Component> components = null;
	
	public Entity(String id){
		this.id = id;
		
		components = new ArrayList<Component>();
		
		position = new Vector2f(0,0);
		scale = 1.0f;
		rotation = 0.0f;
	}
	
	public void update(GameContainer container, StateBasedGame game, int delta){
		for(Component c:components){
			c.update(container, game, delta);
		}
	}
	
	public void render(GameContainer container, StateBasedGame game, Graphics g){
		if(renderComponent != null){
			renderComponent.render(container, game, g);
		}
	}
	
	public void addComponent(Component component){
		if(RenderComponent.class.isInstance(component)){
			renderComponent = (RenderComponent)component;
		}
		
		component.setParentEntity(this);
		components.add(component);
	}
	
	public Component getComponent(String id){
		for(Component c:components){
			if(c.getId().equalsIgnoreCase(id)){
				return c;
			}
		}
		return null;
	}
	
	public Vector2f getPosition(){
		return position;
	}
	
	public float getScale(){
		return scale;
	}
	
	public float getRotation(){
		return rotation;
	}
	
	public String getId(){
		return id;
	}
	
	public void setPosition(Vector2f newPosition) {
		this.position = newPosition;
    }
 
    public void setRotation(float newRotation) {
        rotation = newRotation;
    }
 
    public void setScale(float newScale) {
    	this.scale = newScale;
    }
	    
	
}
